package com.fishingwithme.android.ui.theme

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.graphics.Color
import com.fishingwithme.android.data.local.PreferencesManager
import com.fishingwithme.android.ui.theme.AppColors

// Color scheme redesigned based on 汽水音乐 actual UI screenshot
private val FishingLightColorScheme = lightColorScheme(
    primary = AppColors.PRIMARY, // Green from 汽水音乐 UI
    onPrimary = AppColors.WHITE,
    primaryContainer = AppColors.PRIMARY_LIGHT,
    onPrimaryContainer = AppColors.PRIMARY_DARK,
    secondary = AppColors.SECONDARY,
    onSecondary = AppColors.WHITE,
    secondaryContainer = AppColors.SECONDARY_LIGHT,
    onSecondaryContainer = AppColors.SECONDARY_DARK,
    tertiary = AppColors.TERTIARY,
    onTertiary = AppColors.WHITE,
    tertiaryContainer = AppColors.TERTIARY_LIGHT,
    onTertiaryContainer = AppColors.TERTIARY_DARK,
    error = AppColors.ERROR,
    errorContainer = AppColors.ERROR_LIGHT,
    onError = AppColors.WHITE,
    onErrorContainer = AppColors.ERROR_DARK,
    background = AppColors.BACKGROUND_LIGHT, // White background
    onBackground = AppColors.TEXT_PRIMARY, // Dark text
    surface = AppColors.SURFACE_LIGHT, // White surface
    onSurface = AppColors.TEXT_PRIMARY, // Dark text
    surfaceVariant = AppColors.SURFACE_VARIANT_LIGHT,
    onSurfaceVariant = AppColors.TEXT_SECONDARY,
    outline = AppColors.OUTLINE_LIGHT,
    inverseOnSurface = AppColors.WHITE,
    inverseSurface = AppColors.TEXT_PRIMARY,
    inversePrimary = Color(0xFF74D8A7), // 这个值在StyleConstants中没有直接对应，保留原值
    surfaceTint = AppColors.PRIMARY,
    outlineVariant = AppColors.OUTLINE_VARIANT_LIGHT,
    scrim = AppColors.BLACK,
)

private val FishingDarkColorScheme = darkColorScheme(
    primary = AppColors.PRIMARY, // Green from 汽水音乐 UI
    onPrimary = AppColors.WHITE,
    primaryContainer = AppColors.PRIMARY_DARK,
    onPrimaryContainer = AppColors.PRIMARY_LIGHT,
    secondary = AppColors.SECONDARY_LIGHT,
    onSecondary = AppColors.SECONDARY_DARK,
    secondaryContainer = AppColors.SECONDARY_DARK,
    onSecondaryContainer = AppColors.SECONDARY_LIGHT,
    tertiary = AppColors.TERTIARY_LIGHT,
    onTertiary = AppColors.TERTIARY_DARK,
    tertiaryContainer = AppColors.TERTIARY_DARK,
    onTertiaryContainer = AppColors.TERTIARY_LIGHT,
    error = Color(0xFFFFCDD2), // 这个值在StyleConstants中没有直接对应，保留原值
    errorContainer = AppColors.ERROR_DARK,
    onError = AppColors.WHITE,
    onErrorContainer = AppColors.ERROR_LIGHT,
    background = AppColors.BACKGROUND_DARK, // Slightly brighter dark background
    onBackground = AppColors.TEXT_LIGHT, // Light text
    surface = AppColors.SURFACE_DARK, // Dark surface for cards
    onSurface = AppColors.TEXT_LIGHT, // Light text on surfaces
    surfaceVariant = AppColors.SURFACE_VARIANT_DARK, // Sidebar background color
    onSurfaceVariant = AppColors.SECONDARY_LIGHT,
    outline = AppColors.OUTLINE_DARK,
    inverseOnSurface = Color(0xFF121212), // 这个值在StyleConstants中没有直接对应，保留原值
    inverseSurface = AppColors.TEXT_LIGHT,
    inversePrimary = Color(0xFF74D8A7), // 这个值在StyleConstants中没有直接对应，保留原值
    surfaceTint = AppColors.PRIMARY,
    outlineVariant = AppColors.OUTLINE_VARIANT_DARK,
    scrim = AppColors.BLACK,
)

@Composable
fun FishingWithMeTheme(
    themeMode: String = PreferencesManager.THEME_FOLLOW_SYSTEM,
    content: @Composable () -> Unit
) {
    val isDarkTheme = when (themeMode) {
        PreferencesManager.THEME_DARK -> true
        PreferencesManager.THEME_LIGHT -> false
        else -> isSystemInDarkTheme() // Follow system
    }

    val colorScheme = when {
        isDarkTheme -> FishingDarkColorScheme
        else -> FishingLightColorScheme
    }

    MaterialTheme(
        colorScheme = colorScheme,
        typography = Typography(),
        content = content
    )
}